package com.example.social.controller;

import com.example.social.common.Result;
import com.example.social.dto.UserDTO;
import com.example.social.service.FriendshipService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/friend")
@RequiredArgsConstructor
@PreAuthorize("isAuthenticated()")
public class FriendshipController {

    private final FriendshipService friendshipService;

    @GetMapping("/list")
    public Result<Map<String, List<UserDTO>>> getFriendList() {
        return Result.success(friendshipService.getFriendList());
    }

    @PostMapping("/add")
    public Result<Void> addFriend(@RequestBody Map<String, Long> request) {
        Long userId = request.get("friendId");
        friendshipService.addFriend(userId);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result<Void> deleteFriend(@PathVariable Long id) {
        friendshipService.deleteFriend(id);
        return Result.success();
    }
} 